<template>
	<view class="orderlist">
		<view class="tabsBox">
			<view class="" style="display: flex;align-items: center;width: 100%;" @click="show = true">
				<view class="">
					{{address}}
				</view>
				<image class="" src="@/static/image/bottoms.png"
					style="width: 40rpx;height: 40rpx;margin-left: 10rpx;" />
			</view>
			<view class="tabs">
				<view class="tabsitem" @click="handleTabs(0)">
					<image v-if="currIndex == 0" class="" src="@/static/image/alled.png"
						style="width: 48rpx;height: 48rpx;" />
					<image v-else class="" src="@/static/image/all.png" style="width: 48rpx;height: 48rpx;" />
					<view class="" :class="{colored: currIndex == 0}">
						全部
					</view>
				</view>
			<!-- 	<view class="tabsitem" @click="handleTabs(1)">
					<image v-if="currIndex == 1" class="" src="@/static/image/bdzed.png"
						style="width: 48rpx;height: 48rpx;" />
					<image v-else class="" src="@/static/image/bdz.png" style="width: 48rpx;height: 48rpx;" />
					<view class="" :class="{colored: currIndex == 1}">
						未支付
					</view>
				</view> -->
				<view class="tabsitem" @click="handleTabs(2)">
					<image v-if="currIndex == 2" class="" src="@/static/image/dsd.png"
						style="width: 48rpx;height: 48rpx;" />
					<image v-else class="" src="@/static/image/dsded.png" style="width: 48rpx;height: 48rpx;" />
					<view class="" :class="{colored: currIndex == 2}">
						已支付
					</view>
				</view>
				<view class="tabsitem" @click="handleTabs(3)">
					<image v-if="currIndex == 3" class="" src="@/static/image/ysded.png"
						style="width: 48rpx;height: 48rpx;" />
					<image v-else class="" src="@/static/image/ysd.png" style="width: 48rpx;height: 48rpx;" />
					<view class="" :class="{colored: currIndex == 3}">
						未送单
					</view>
				</view>
				<view class="tabsitem" @click="handleTabs(4)">
					<image v-if="currIndex == 4" class="" src="@/static/image/yhked.png"
						style="width: 48rpx;height: 48rpx;" />
					<image v-else class="" src="@/static/image/yhk.png" style="width: 48rpx;height: 48rpx;" />
					<view class="" :class="{colored: currIndex == 4}">
						已送单
					</view>
				</view>
			<!-- 	<view v-if="identity == 0" class="tabsitem" @click="handleTabs(4)">
					<image v-if="currIndex == 4" class="" src="@/static/image/yhked.png"
						style="width: 48rpx;height: 48rpx;" />
					<image v-else class="" src="@/static/image/yhk.png" style="width: 48rpx;height: 48rpx;" />
					<view class="" :class="{colored: currIndex == 4}">
						已回款
					</view>
				</view> -->
			</view>

		</view>


		<view class="dataList">
			<view v-if="dataList.length>0" class="">
				<view class="outbox" v-for="(item,index) in dataList">
					<view class="orderNumber">
						<view class="">
							手机号：
						</view>
						<view class="">
							{{item.mobile}}
						</view>
						<view v-if="currIndex == 3" class="status">
							<image class="" src="@/static/image/ysz.png" style="width: 45.55rpx;height: 48rpx;" />
							<view class="" style="margin-left: 10rpx;">
								运输中
							</view>
						</view>
						<!-- <view v-if="currIndex == 4" class="payment">
							<view class="">
								剩余7天
							</view>
						</view> -->
					</view>
					<view class="contentBox">
						<view class="innerBox">
							<view class="info">
								<view class="avatar">
									<image class="" src="@/static/image/lovespecialist.png"
										style="width: 45.55rpx;height: 45.55rpx;" />
								</view>
								<view class="nikename">
									{{item.name}}
								</view>
							</view>

							<view class="message">
								<view class="name">
									{{item.good.name}}
								</view>
								<!-- <view class="shuliang">
									{{subitem.good_info.capacity}}L
								</view> -->
							</view>
							<view class="sumandnum">
								<view class="sum">
									￥{{item.good.price}}
								</view>
								<view class="num" style="color: #A7A7A7;">
									x{{item.count}}
								</view>
							</view>
						</view>

						<view class="dfk">
							<!-- <view v-if="item.status!=4" class="">
								待收款：￥{{item.sumPrice}}
							</view> -->
							<view v-if="item.status == 0" class="status">
								订单状态：待支付
							</view>
							<view v-if="item.status == 1" class="status">
								订单状态：已支付
							</view>
							<view v-if="item.status == 2" class="status">
								订单状态：待送单
							</view>
							<view v-if="item.status == 3" class="status" style="color: red;">
								订单状态：已送单
							</view>
							<!-- <view v-if="item.status == 4" class="status">
								订单状态：已回款
							</view> -->
							<!-- {{item.status}} -->
						</view>
						<view class="dfk">
							收货地址：{{item.town}}{{item.village}}
							<!-- {{item.province}}{{item.city}}{{item.district}} -->
						</view>
					</view>

					<view v-if="currIndex > 2" class="driver">
						<view class="">
							司机：
						</view>
						<view class="">
							{{item.driver.name}}—{{item.driver.account}}
						</view>
					</view>
				</view>
			</view>

			<view v-else class="">
				<u-empty text="暂无订单" icon="http://cdn.uviewui.com/uview/empty/order.png">
				</u-empty>
			</view>
		</view>

		<view class="" style="height: 200rpx;"></view>

		<u-picker :show="show" ref="uPicker" :columns="columns" @confirm="confirm" @change="changeHandler"
			@cancel="show = false"></u-picker>

	</view>
</template>

<script>
	import {
		submitorderList,
		createorder,
		orderList,
		payment,
		salerList,
		getregion,
	} from "@/api/api.js"
	export default {
		data() {
			return {
				currIndex: 0,
				show: false,
				identity: null,
				declarationFlag: false,
				dataList: [],
				baodanLenght: 0,
				orderId: null,
				address: "请选择村庄",
				columns: [
					[],
					[],
					[],
					[],
					[]
				],
				province: [], //省
				sheng: [],
				city: [], //市
				shi: [],
				area: [], //区县
				qu: [],
				township: [], //乡镇
				xiangzhen: [],
				hamlet: [], //村庄
				cunzhuang: [],
				shengCode: null, //省id
				shiCode: null, //市id
				quCode: null, //区id
				xiangzhenCode: null, //乡镇id
				cunzhuangCode: null, //村庄code
				level: "", //地区级别1-5省市县镇村
				region: "", //地区
				pageSize: 10,
				page: 1,
			}
		},
		onLoad() {
			this.identity = uni.getStorageSync("identity")
			this.getorderList()
			this.handleGetregion()
		},
		methods: {



			async getorderList() {
				let res = await orderList({
					page_size: this.pageSize,
					page: this.page,
					region: this.region,
					level: this.level,
				})
				console.log("订单列表", res)
				this.dataList = []

				res.data.data.forEach((item, index) => {
					// let sum = 0
					// item.pre_orders.forEach((subitem, subindex) => {
					// 	sum += (subitem.count * subitem.good_info.price)
					// })
					// item.sumPrice = sum
					// console.log("status", this.currIndex, item.status)
					if (this.currIndex == 0) {
						this.dataList.push(item)
					} else {
						if ((this.currIndex - 1) == item.status) {
							this.dataList.push(item)
						}
					}

					// if (this.currIndex == 1) {
					// 	if (item.status == 0) {
					// 		this.dataList.push(item)
					// 	}
					// }
					// if (this.currIndex == 2) {
					// 	if (item.status == 1) {
					// 		this.dataList.push(item)
					// 	}
					// }
					// if (this.currIndex == 3) {
					// 	if (item.status == 2) {
					// 		this.dataList.push(item)
					// 	}
					// }
					// if (this.currIndex == 4 && this.identity == 1) {
					// 	if (item.status == 3) {
					// 		this.dataList.push(item)
					// 	}
					// }
					// if (this.currIndex == 4 && this.identity == 0) {
					// 	if (item.status == 4) {
					// 		this.dataList.push(item)
					// 	}
					// }

				})
				console.log("dataList", this.dataList)
			},
			handleTabs(index) {
				this.currIndex = index
				this.dataList = []
				this.getorderList()
			},
			handleOpenShow(id) {
				console.log("444444444", id)
				this.show = true
				this.orderId = id
			},

			async handleGetregion() {
				let res = await getregion()
				console.log("省市区", res)
				res.data.forEach((item, index) => {
					this.province.push(item.name)
					this.sheng.push(item.code)
				})
				this.columns[0] = this.province
			},

			async changeHandler(e) {
				// console.log("eeee", e)
				const {
					columnIndex,
					value,
					values, // values为当前变化列的数组内容
					index,
					picker = this.$refs.uPicker
				} = e

				//获取市
				if (columnIndex === 0) {
					this.city = []
					this.shi = []

					this.shengCode = this.sheng[index]
					// this.shengName = this.province[index]
					uni.showToast({
						title: this.province[index],
						icon: "none",
						duration: 1500
					});
					// console.log("shengCode", shengCode)
					let res = await getregion({
						parent_code: this.shengCode
					})
					// console.log("市", res)
					res.data.forEach((item, index) => {
						this.city.push(item.name)
						this.shi.push(item.code)
					})
					this.columns[1] = this.city
					this.columns[2] = []
					this.columns[3] = []
					this.columns[4] = []
				}

				//获取区
				if (columnIndex === 1) {
					this.area = []
					this.qu = []

					this.shiCode = this.shi[index]
					uni.showToast({
						title: this.city[index],
						icon: "none",
						duration: 1500
					});
					let res = await getregion({
						parent_code: this.shiCode
					})
					res.data.forEach((item, index) => {
						this.area.push(item.name)
						this.qu.push(item.code)
					})
					this.columns[2] = this.area
					this.columns[3] = []
					this.columns[4] = []
				}

				//乡镇
				if (columnIndex === 2) {
					this.township = []
					this.xiangzhen = []
					this.quCode = this.qu[index]
					uni.showToast({
						title: this.area[index],
						icon: "none",
						duration: 1500
					});
					let res = await getregion({
						parent_code: this.quCode
					})
					res.data.forEach((item, index) => {
						this.township.push(item.name)
						this.xiangzhen.push(item.code)
					})
					this.columns[3] = this.township
					this.columns[4] = []
				}

				//村庄
				if (columnIndex === 3) {
					this.hamlet = []
					this.cunzhuang = []
					this.xiangzhenCode = this.xiangzhen[index]
					uni.showToast({
						title: this.township[index],
						icon: "none",
						duration: 1500
					});
					let res = await getregion({
						parent_code: this.xiangzhenCode
					})
					res.data.forEach((item, index) => {
						this.hamlet.push(item.name)
						this.cunzhuang.push(item.code)
					})
					this.columns[4] = this.hamlet
				}


				if (columnIndex === 4) {
					this.cunzhuangCode = this.cunzhuang[index]
					uni.showToast({
						title: this.hamlet[index],
						icon: "none",
						duration: 1500
					});
					// console.log("55555555")
				}
			},
			confirm(e) {
				console.log("e", e)
				this.address = ""
				e.value.forEach((item, index) => {
					if (item != undefined) {
						this.address += item
						this.level = index + 1
						this.region = item
					}
				})
				console.log("address", this.address, this.region, this.level)
				this.show = false
				this.getorderList()


			},



		}
	}
</script>

<style scoped lang="scss">
	.subAddress {
		width: 686rpx;
		height: 500rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 8rpx 52rpx 0rpx rgba(0, 0, 0, 0.12);
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		padding: 90rpx 30rpx;
		box-sizing: border-box;

		.title {
			font-size: 50rpx;
			font-family: PingFang SC-Semibold, PingFang SC;
			font-weight: 600;
			color: #000000;
			line-height: 50rpx;
			text-align: center;
		}

		.content {
			margin-top: 50rpx;
			font-size: 50rpx;
			font-family: PingFang SC-Semibold, PingFang SC;
			font-weight: 600;
			color: #000000;
			line-height: 50rpx;
			text-align: center;
		}

		.bottomBtn {
			display: flex;
			justify-content: space-between;
			margin-top: 84rpx;

			.btnleft {
				width: 184rpx;
				height: 88rpx;
				background: #A7A7A7;
				border-radius: 60rpx 60rpx 60rpx 60rpx;
				font-size: 48rpx;
				font-family: PingFang SC-Semibold, PingFang SC;
				font-weight: 600;
				color: #FFFFFF;
				line-height: 50rpx;
				text-align: center;
				line-height: 88rpx;
			}

			.btnright {
				width: 406rpx;
				height: 88rpx;
				background: linear-gradient(180deg, #FE5C5C 0%, rgba(255, 78, 78, 0.67) 100%);
				border-radius: 60rpx 60rpx 60rpx 60rpx;
				font-size: 48rpx;
				font-family: PingFang SC-Semibold, PingFang SC;
				font-weight: 600;
				color: #FFFFFF;
				line-height: 50rpx;
				text-align: center;
				line-height: 88rpx;
			}
		}
	}

	.orderlist {
		.tabsBox {
			width: 702rpx;
			height: 250rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 0rpx 8rpx 2rpx rgba(0, 0, 0, 0.05);
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			margin: 24rpx auto;
			padding: 16rpx;
			box-sizing: border-box;

			.title {
				font-size: 32rpx;
				font-family: PingFang SC-Semibold, PingFang SC;
				font-weight: 600;
				color: #000000;
				line-height: 50rpx;
			}

			.tabs {
				display: flex;
				width: 100%;
				padding: 30rpx;
				box-sizing: border-box;
				justify-content: space-between;
				font-size: 28rpx;
				font-family: PingFang SC-Semibold, PingFang SC;
				font-weight: 600;
				color: #000000;
				line-height: 50rpx;

				.tabsitem {
					text-align: center;
				}
			}

			.colored {
				color: #FF4E4E;
			}
		}

		.dataList {


			.outbox {
				width: 702rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 0rpx 8rpx 0rpx rgba(0, 0, 0, 0.05);
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				margin: 0 auto;
				padding: 16rpx 24rpx;
				box-sizing: border-box;
				margin-bottom: 24rpx;

				.orderNumber {
					font-size: 24rpx;
					font-family: PingFang SC-Semibold, PingFang SC;
					font-weight: 600;
					color: #000000;
					line-height: 50rpx;
					display: flex;

					.status {
						display: flex;
						margin-left: 180rpx;
					}

					.payment {
						font-size: 24rpx;
						font-family: PingFang SC-Semibold, PingFang SC;
						font-weight: 600;
						color: #FF4E4E;
						line-height: 50rpx;
						display: flex;
						margin-left: 230rpx;

						.paymentbtn {
							width: 120rpx;
							height: 50rpx;
							background: #FF4E4E;
							border-radius: 16rpx 16rpx 16rpx 16rpx;
							font-size: 24rpx;
							font-family: PingFang SC-Semibold, PingFang SC;
							font-weight: 600;
							color: #FFFFFF;
							line-height: 50rpx;
							text-align: center;
						}
					}

				}

				.driver {
					font-size: 24rpx;
					font-family: PingFang SC-Semibold, PingFang SC;
					font-weight: 600;
					color: #000000;
					line-height: 50rpx;
					display: flex;
				}

				.contentBox {
					width: 666rpx;
					background: #FFFFFF;
					box-shadow: 0rpx 0rpx 8rpx 2rpx rgba(0, 0, 0, 0.05);
					border-radius: 16rpx 16rpx 16rpx 16rpx;
					padding: 18rpx 16rpx;
					box-sizing: border-box;
					margin-bottom: 16rpx;
					margin-top: 10rpx;

					.innerBox {
						display: flex;
						justify-content: space-between;

						.info {
							display: flex;
							font-size: 28rpx;
							font-family: PingFang SC-Semibold, PingFang SC;
							font-weight: 600;
							color: #000000;
							line-height: 50rpx;
						}

						.message {
							.name {
								width: 320rpx;
								height: 50rpx;
								font-size: 24rpx;
								font-family: PingFang SC-Regular, PingFang SC;
								font-weight: 400;
								color: #000000;
								line-height: 50rpx;
								white-space: nowrap;
								overflow: hidden;
								text-overflow: ellipsis;
							}

							.shuliang {
								font-size: 24rpx;
								font-family: PingFang SC-Regular, PingFang SC;
								font-weight: 400;
								color: #A7A7A7;
								line-height: 50rpx;
							}

						}

						.sumandnum {
							font-size: 24rpx;
							font-family: PingFang SC-Regular, PingFang SC;
							font-weight: 400;
							color: #000000;
							line-height: 50rpx;
							text-align: right;
						}
					}

					.dfk {
						font-size: 28rpx;
						font-family: PingFang SC-Semibold, PingFang SC;
						font-weight: 600;
						color: #000000;
						line-height: 50rpx;
						// text-align: right;
						display: flex;
						justify-content: space-between;

					}
				}
			}
		}
	}

	.bottomContent {
		width: 100%;
		background: #FFFFFF;
		position: fixed;
		bottom: 0;
		padding: 20rpx 40rpx;
		box-sizing: border-box;
		padding-bottom: constant(safe-area-inset-bottom);
		/* 兼容 iOS 设备 */
		padding-bottom: env(safe-area-inset-bottom);
		display: flex;
		justify-content: space-between;

		.left {
			font-size: 40rpx;
			font-family: PingFang SC-Semibold, PingFang SC;
			font-weight: 600;
			color: #A7A7A7;
			line-height: 50rpx;
			display: flex;
		}

		.right {
			width: 224rpx;
			height: 90rpx;
			background: linear-gradient(180deg, #FE5C5C 0%, rgba(255, 78, 78, 0.67) 100%);
			border-radius: 60rpx 60rpx 60rpx 60rpx;
			font-size: 40rpx;
			font-family: PingFang SC-Semibold, PingFang SC;
			font-weight: 600;
			color: #FFFFFF;
			line-height: 90rpx;
			text-align: center;
		}
	}
</style>